package com.tucc.hello.leetcode.no1_400.no1_200.no61_80.no80;

/**
 * @author tucc
 * @description todo
 * @package com.tucc.hello.leetcode
 * @date 2021/5/20
 **/
public class Solution {

    public static void main(String[] args) {
        Solution solution = new Solution();
        int[] nums = {1, 2, 2, 3, 3, 3, 4, 4, 4};
        int left = solution.removeDuplicates(nums);
        for (int i = 0; i < left; i++) {
            System.out.print(nums[i] + " ");
        }
        System.out.println();
    }

    public int removeDuplicates(int[] nums) {
        int len = nums.length;
        int cur = 1;
        int repeat = Integer.MAX_VALUE;
        for (int i = 1; i < nums.length; i++) {
            if (nums[i] == nums[i - 1]) {
                if (repeat == nums[i]) {
                    len--;
                } else {
                    repeat = nums[i];
                    nums[cur++] = nums[i];
                }
            } else {
                repeat = Integer.MAX_VALUE;
                nums[cur++] = nums[i];
            }
        }
        return len;
    }
}
